<?php
/**
 * Add/Updade Job Workflow Steps Grid
 * 
 * @author Xavier VILAIN
 * @package Hive\Mission\Workflow
 * @license #hive-missions#
 * 
 */

// Steps List
use Fox\Generator;
use Fox\Behaviors;
use Fox\Html\Button;

$xview = Xview::instance();
$reload = $xview->val('reload');
$inlineid = Xview::instance()->val('inlineid');
$grid = new Fox\Grid('steps',Generator::url('missions','workflows','steps',array('inlineid' => $inlineid,'reload'=> true)));
$grid->fieldcat(array(
				array('workflow_position','position')
				,'label',
				array('workflow_step_type','type'),'idele'));
$grid->fieldcat()->switchToObjectMode()
		->behaviors(Behaviors::value('draggable'));

foreach(\Fox\Dao::finder(Hive\Workflow\Type::className())->find() as $type) {
	$typeLabels[$type->type] = $type->label();
}

$grid->fieldcat()->setGenerators(array(
	'idele' => Generator::useValue('?'),
	'type' => Generator::useFunction(function($data) use($typeLabels){
		return $typeLabels[$data->type];
	})
));
$grid->fieldcat()->field('position')->setClass('position')
->headerAlign('center')
	->align('center');
$grid->fieldcat()->setFieldAttr(array('position','label','type'), 'setHiddenInput',true);
$grid->footer(new Button('add'))
		->label(Msg(Hive::BUNDLE,Hive::MISSION_WORKFLOW_ADD_STEP))
		->behaviors(Behaviors::action(
			Generator::url('missions','workflow','step'),true
		));
if($reload) {
	// Handle Posted Data 
}
return $grid;